package com.foryou.wechat.controller;

import com.alibaba.fastjson.JSONObject;
import com.foryou.wechat.model.Query;
import com.foryou.wechat.model.dto.ProductionDTO;
import com.foryou.wechat.service.ProductionService;
import com.foryou.wechat.utils.HttpContextUtils;
import com.foryou.wechat.utils.Response;
import com.foryou.wechat.utils.ValidatorUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by Lee.
 */
@RestController
@RequestMapping("/v/production")
public class ProductionController {

    private final ProductionService productionService;

    public ProductionController(ProductionService productionService) {
        this.productionService = productionService;
    }

    @PostMapping("/addProduction")
    public Response addProduction(@RequestBody ProductionDTO productionDTO) {
        ValidatorUtils.validateEntity(productionDTO);
        return productionService.addProduction(productionDTO);
    }

    @GetMapping("/getProductionDetail")
    public Response getProductionDetail(Long productionId) {
        return productionService.getProductionDetail(productionId);
    }

    @PostMapping("/getForProductionDetail/{id}")
    public JSONObject getForProductionDetail(@PathVariable("id") Long productionId) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("data", productionService.getProductionDetail(productionId).getData());
        return jsonObject;
    }

    @PostMapping("/getProductionList")
    public Response getProductionList(@RequestBody Query query) {
        return productionService.getProductionList(query);
    }

    @GetMapping("/collectProduction")
    public Response collectProduction(Long productionId) {
        return productionService.collectProduction(productionId);
    }

    @GetMapping("/cancelProduction")
    public Response cancelProduction(Long productionId) {
        return productionService.cancelProduction(productionId);
    }

    @GetMapping("/queryCollectProductionList")
    public Response getCollectPlaceList(@RequestParam(defaultValue = "0") int start) {
        return productionService.queryCollectProduction(start, HttpContextUtils.getUserId());
    }

    @GetMapping("/pushOneUser")
    public void pushOneUser(Long productionId,int status) {

    }
}
